﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Tilver.Net;

namespace Tilver.WinTest
{
    public class AsyncTaskUI : Task
    {
        /// <summary>
        /// 用于触发异常
        /// </summary>
        public int errorkey = 1;
        protected override object Execute(params object[] args)
        {
            for (int i = 0; i < 100; i++)
            {
                if (_taskState == TaskStatus.CancelPending)
                {
                    break;
                }
                if (errorkey == 0)
                {
                    errorkey = i / errorkey;
                }
                Thread thread = Thread.CurrentThread;
                if (thread != null)
                    Console.WriteLine("线程号:[{0}],线程名称:[{1}],线程状态:[{2}],当前时间:[{3}],循环次数:[{4}].", thread.Name, thread.GetHashCode(), "", DateTime.Now.ToLongTimeString(), i.ToString());
                else
                    Console.WriteLine("线程号:[{0}],线程名称:[{1}],线程状态:[{2}],当前时间:[{3}],循环次数:[{4}].", "", "", "", DateTime.Now.ToLongTimeString(), i.ToString());
                Thread.Sleep(1000 * 1);
                this.ProgressChangedEvent(i, i);
            }
            return 100;
        }
        /*
        public override object Work(params object[] args)
        {
            base.Work(args);
            for (int i = 0; i < 100; i++)
            {
                if (_taskState == TaskStatus.CancelPending)
                {
                    break;
                }
                if (errorkey == 0)
                {
                    errorkey = i / errorkey;
                }
                Thread thread = Thread.CurrentThread;
                if (thread != null)
                    Console.WriteLine("线程号:[{0}],线程名称:[{1}],线程状态:[{2}],当前时间:[{3}],循环次数:[{4}].", thread.Name, thread.GetHashCode(), "", DateTime.Now.ToLongTimeString(), i.ToString());
                else
                    Console.WriteLine("线程号:[{0}],线程名称:[{1}],线程状态:[{2}],当前时间:[{3}],循环次数:[{4}].", "", "", "", DateTime.Now.ToLongTimeString(), i.ToString());
                Thread.Sleep(1000 * 1);
                this.ProgressChangedEvent(i, i);
            }
            return 100;
        }
        public object Work2(params object[] args)
        {
            base.Work(args);
            for (int i = 0; i < 100; i++)
            {
                if (_taskState == TaskStatus.CancelPending)
                {
                    break;
                }
                if (errorkey == 0)
                {
                    errorkey = i / errorkey;
                }
                Thread thread = Thread.CurrentThread;
                if (thread != null)
                { Console.WriteLine("线程号:[{0}],线程名称:[{1}],线程状态:[{2}],当前时间:[{3}],循环次数:[{4}].", thread.Name, thread.GetHashCode(), "", DateTime.Now.ToLongTimeString(), i.ToString()); }
                else
                { Console.WriteLine("线程号:[{0}],线程名称:[{1}],线程状态:[{2}],当前时间:[{3}],循环次数:[{4}].", "", "", "", DateTime.Now.ToLongTimeString(), i.ToString()); }
                Thread.Sleep(1000 * 1);
                this.ProgressChangedEvent(i, i);
            }
            return 100;
        }

        */
    }

}
